<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>تفاصيل وصل الطلب</title>

<!------------------------------ajax---------------------------->
<!-- <script type="text/javascript"  src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
    <script type="text/javascript"  src="http://malsup.github.com/jquery.form.js"></script> -->
	
<!---------------------for autocomplete--------------->
	<script type="text/javascript" src="<?php echo base_url('assets/js/jquery-1.11.0.min.js');?>" ></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/jquery-ui-1.10.4/js/jquery-ui-1.10.4.min.js');?>" ></script>
	<link href="<?php echo base_url("assets/css/jquery-ui.css")?>" rel="stylesheet" type="text/css" />
<!---------------------for form css ----------------------->
	<link href="<?php echo base_url("assets/css/pure.css")?>" rel="stylesheet" type="text/css" />
<!---------------------for form validation ----------------------->
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery.validate.js');?>" ></script>
<!---------------------for form mask input ----------------------->
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery.mask.min.js');?>" ></script>


</head>
<body>
<?php
include_once('header.php');
$result=$les_bc;  // one fournisseur
$fournisseur=$fournisseurs;  // list of all fournisseur for autocomplete
$produit=$produits;

// ----- populate $liste_des_fournisseurs array for autocomplete ----- //
$liste_des_fournisseurs = array();
foreach ($fournisseur as $lf){
	array_push($liste_des_fournisseurs, $lf->nom);
}

$liste_des_produit = array();

if($produit)
foreach ($produit as $prod){
	array_push($liste_des_produit, $prod->dessignation);
}
// ----- populate $liste_des_activites array for autocomplete ----- //


?>
<?php
//echo form_open_multipart( base_url('bc_ctr/modifier_prod').'/'.$result[0]->id_bc ); 
if($rmq==1){
	//echo("il faul faire convention");
	echo '<div style="background:red; font-size:150%"><a href='.base_url("/bc_ctr/ajout_convention_regularise").'/'.$result[0]->id_bc.'/'.$result[0]->id_fournisseur.'> يجب انجاز اتفاقية تسوية</a></div>';
}
$montant_milier = number_format($montant, 2, ',', ' ');
?>

<form id="bc_form" class="pure-form pure-form-stacked" method="POST" action="<?php echo base_url('bc_ctr/modifier_bc').'/'.$result[0]->id_bc;?>">
    
        <legend style="font-size: 150%"> وصل طلب رقم : <?php echo('<strong>'.$result[0]->numero.'</strong>');?></legend>

        <div class="pure-g">
            <div class="pure-u-1 pure-u-md-1-3" style="width: 30%">
                <label for="fournisseur" style="display: inline-block">اسم المورد : </label>
				<label  style="display: inline-block"><?php echo($result[0]->nom);?></label>
            </div>
            
			 <div class="pure-u-1 pure-u-md-1-3 " style="width: 30%">
                <label for="numero" style="display: inline-block"> المبلغ : </label>
				<label style="display: inline-block" class="ltr"><?php echo($montant_milier);?></label>
                
            </div>
			
            <div class="pure-u-1 pure-u-md-1-3 " style="width: 30%">
                <label style="display: inline-block" for="article">التاريخ </label>
                <input  style="display: inline-block" class="ltr" id="article" name="date" type="text" value="<?php echo($result[0]->date);?>">
            </div>
			
			 <div class="pure-u-1 pure-u-md-1-3 " style="width: 30%">
                <label style="display: inline-block" for="article">الرقم </label>
                <input  style="display: inline-block" class="ltr" id="article" name="numero" type="text" value="<?php echo($result[0]->numero);?>">
            </div>

           
			
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 90%">
                <label for="numero" style="display: inline-block"> المبلغ بالحروف :</label>
				<?php echo($lettre);?>
                
            </div>
			
</div>			
			
<div class="pure-u-1 pure-u-md-1-3 " style="width: 50%">			
			     <?php
  $goupe=$this->session->userdata('user_group'); //access it
if($goupe=="admin"){
echo ('<input type="submit" id="ajouter" value="تسجيل التغييرات"  class="pure-button pure-button-primary"  />


<a href="'. base_url("/bc_ctr/imprimer").'/'.$result[0]->id_bc.'/'.$result[0]->id_fournisseur.'" class="pure-button pure-button-primary">طباعة</a>
');
if(!$result[0]->num_engagement AND $montant<500000){
	echo('<a href="'. base_url("/bc_ctr/mise_a_jour_bc").'/'.$result[0]->id_bc.'/'.$result[0]->id_article_fk.'" class="pure-button pure-button-primary">التزام</a>
	<a href="'. base_url("/bc_ctr/ajout_produit").'/'.$result[0]->id_bc.'/'.$result[0]->id_fournisseur.'" class="pure-button pure-button-primary">اضافة منتج</a>');
	
}
}else{
	echo ('<a href="#" class="pure-button-disabled pure-button-primary">تسجيل التغييرات</a>
	<a href="#" class="pure-button-disabled pure-button-primary">اضافة منتج</a>');
}
?>
		

   
     <a href="<?php echo base_url("/bc_ctr/")?>" class="pure-button pure-button-primary" >خروج</a>
	  <a <?php echo(' href=" '.  base_url("/bc_ctr/supprimer_bc/").'/'.$result[0]->id_bc .' " ');?> class="pure-button pure-button-primary" onclick="return confirm('هل تريد فعلا حذف هذا الوصل ');">حذف</a>
	 </div>
</form>
		
<?php

if($montant>0){ // test si il ya des produit dans le bc avant afficher
$i=0;
echo('<div id="les prod" style="width: 90%; text-align: center; letter-spacing:0.5px;">
			<br>
			  <label style="font-size:150% ">	المنتجات التابعة لهذا الوصل </label>
				
			<br>
			</div>');	
foreach($result as $data) 
{
	$i++;
$table['num_prod']=$i;
$table['id_bc']=$data->id_bc;
$table['id_bc_prod']=$data->id_bc_produit;
$prix=($data->bc_produit_pu * $data->quantite)+(($data->bc_produit_pu * $data->quantite)*$data->tva/100);
$prix_milier = number_format($prix, 2, ',', ' ');

  $goupe=$this->session->userdata('user_group'); //access it


if($goupe=="admin" AND !$result[0]->num_engagement){ // si il est administrateur on affiche des bottons
 echo '
 <form id="bc_form"  method="POST" action="'.base_url('bc_ctr/modifier_prod').'/'.$i.'/'.$data->id_bc.'/'.$data->id_bc_produit.'/'.$data->id_fournisseur.'">
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 20%">
                <label for="numero"> المنتج </label>
				<input class="ltr" id="dessignation'.$i.'" name="dessignation'.$i.'" type="text" value="'.$data->dessignation.'">
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero">س و</label>
				<input class="ltr" id="pu" name="pu'.$i.'" type="text" value="'.$data->bc_produit_pu.'">
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero"> الكمية </label>
				<input class="ltr" id="quantite" name="quantite'.$i.'" type="text" value="'.$data->quantite.'">
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero"> المبلغ</label>
				<label style="display: inline-block" class="ltr"> '.$prix_milier.'</label>
				
                
            </div>
			<div  class="pure-u-1 pure-u-md-1-3" " style="width: 20%">
		<input type="submit" id="ajouter" value="تحديث"  class="pure-button pure-button-primary"  />
	   <a href="'.base_url("/bc_ctr/supprime_prod").'/'.$data->id_bc_produit.'/'.$data->id_bc.'/'.$data->id_fournisseur.'" class="pure-button pure-button-primary">حذف</a>
			 </div>
			 </form>
			';
			
	}else{
		 echo '
 <form id="bc_form"  method="POST" action="'.base_url('bc_ctr/modifier_prod').'/'.$i.'/'.$data->id_bc.'/'.$data->id_bc_produit.'/'.$data->id_fournisseur.'">
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 20%">
                <label for="numero"> المنتج </label>
				<label style="display: inline-block" class="ltr">'.$data->dessignation.'</label>
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero">س و</label>
				<label style="display: inline-block" class="ltr">'.$data->bc_produit_pu.'</label>
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero"> الكمية </label>
				<label style="display: inline-block" class="ltr">'.$data->quantite.'</label>
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 20%">
                <label for="numero"> المبلغ </label>
				<label style="display: inline-block" class="ltr"> '.$prix_milier.'</label>
                
            </div>
			
			 </form>
			';
	}		
			

	
}
$i++;
if($goupe=="admin" AND !$result[0]->num_engagement) echo('
<div class="pure-u-1 pure-u-md-1-3 " style="width: 50%">
<a href="'. base_url("/bc_ctr/ajout_produit").'/'.$result[0]->id_bc.'/'.$result[0]->id_fournisseur.'" class="pure-button pure-button-primary">اضافة منتج</a>
</div>');
}else{
	echo '<div class="pure-u-1 pure-u-md-1-3 " " style="background-color:red; font-size: 200%; width:80% ">
                <label for="numero"> لا يوجد منتجات تابعة لهذا الوصل </label>
				               
            </div>';
}
?>
     
		</div>
<?php  
if($goupe=="finance"){ // si il est comtable on affiche des bottons
if(!$result[0]->id_mondat_fk AND $result[0]->num_engagement){// on va tester si le bc est deja payer
	 echo '
 <div>
 <form id="bc_form"  method="POST" action="'.base_url('bc_ctr/payer_bc').'/'.$result[0]->id_bc.'/'.$result[0]->id_fournisseur.'/'.$montant.'">
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 90%; text-align: center; letter-spacing:0.5px; font-size:150%">
                <label for="numero" > خاص بالمحاسب</label>
			
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 40%">
                <label for="numero"> numero mondat </label>
				<input class="ltr" id="dessignation" name="num_mondat" type="text" value="">
                
            </div>
			
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 40%">
                <label for="numero"> numero cheque </label>
				<input class="ltr" id="dessignation" name="num_cheque" type="text" value="">
                
            </div>
			<div class="pure-u-1 pure-u-md-1-3 " " style="width: 40%">
                <label for="numero">numero de facture </label>
				<input class="ltr" id="pu" name="num_facture" type="text" value="">
                
            </div>
			
			
			<div  class="pure-u-1 pure-u-md-1-3" " style="width: 40%">
		<input type="submit" id="ajouter" value="payer"  class="pure-button pure-button-primary"  />
	 
			 </div>
			 </form>
			 </div>
			';
			
	}else{
		if($result[0]->num_engagement){ // le bc est payer
		// on va afficher detaille mondat
		 echo '
 <div>
 <form id="bc_form"  method="POST" action="">
			<div class="pure-u-1 pure-u-md-1-3 "style="width: 90%; text-align: center; letter-spacing:0.5px;font_size:150%;">
                <label for="numero"  > خاص بالمحاسب</label>
			
                
            </div>
			
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 90%">
                <label for="numero"> وصل الطلب هذا قد تم تخليصه </label>
				
                
            </div>
			
			
			
			 </form>
			 </div>
			';
			}else{
			 echo '
 <div>
 <form id="bc_form"  method="POST" action="">
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 90%; text-align: center; letter-spacing:0.5px; font-size:150%">
                <label for="numero" > خاص بالمحاسب</label>
			
                
            </div>
			
			<div class="pure-u-1 pure-u-md-1-3 " style="width: 90%">
                <label for="numero"> لا يوجد التزام خاص بهذا الوصل </label>
				
                
            </div>
			
			
			
			 </form>
			 </div>
			';	
			}
	}
	}
	?>
			

</body>

<script>
$(document).ready(function() {

var liste_fourniss = <?php echo json_encode($liste_des_fournisseurs); ?>;
var liste_prod = <?php echo json_encode($liste_des_produit); ?>;
$( "#nom" ).autocomplete({source: liste_fourniss});
for(j=0;j<7;j++)	{
$( "#dessignation".concat(j) ).autocomplete({source: liste_prod});
}


});

//---



</script>
<script> 
 $(document).ready( function() {
	$('#send').click(function(){
		//    $("#bc_form").submit(function () {
	            $.post("<?php echo base_url("/bc_ctr/test/$i");?>",$("#bc_form").serialize(),function(texte){
	                        $("#ajout").append(texte);
							
					
	            });
				
				
	            return false; // ne change pas de page
				
                  
	    });
				
	});
	

</script>
</html>